package com.med.meddataintegrator.doctor.controller;

import com.med.meddataintegrator.common.basic.response.JsonResult;
import com.med.meddataintegrator.common.pojo.dto.drugs.DrugsParam;
import com.med.meddataintegrator.common.pojo.dto.drugs.DrugsQuery;
import com.med.meddataintegrator.common.pojo.vo.drugs.DrugsVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.med.meddataintegrator.doctor.service.drugsService;

import java.util.List;

@RequestMapping("/drugs")
@RestController
@Slf4j
@Api(tags = "drugs")
public class drugsController {
    @Autowired
    private drugsService drugsservice;

    @GetMapping("list")
    public JsonResult selectDrugs(DrugsQuery drugsQuery){
        log.debug("查询药品：{}",drugsQuery);
        List<DrugsVO> list = drugsservice.selectDrugs(drugsQuery);
        return JsonResult.ok(list);
    }

    @PostMapping("update")
    public JsonResult updateDrugs(@RequestBody DrugsParam drugsParam){
        log.debug("更新药品：{}",drugsParam);
        drugsservice.updateDrugs(drugsParam);
        return JsonResult.ok();
    }
    @PostMapping("del/{id}")
    public JsonResult delDrugs(@PathVariable Integer id){
        log.debug("删除药品：{}",id);
        drugsservice.delDrugs(id);
        return JsonResult.ok();
    }
    @PostMapping("add")
    public JsonResult addDrugs(@RequestBody DrugsParam drugsParam){
        log.debug("添加药品：{}",drugsParam);
        log.info("添加药品：{}",drugsParam);
        System.out.println(drugsParam.toString());
        drugsservice.addDrugs(drugsParam);
        return JsonResult.ok();
    }
}
